import { Component } from '@angular/core';
import { NavController, ModalController } from 'ionic-angular';
import { ShareProvider } from '../../providers/share';

@Component({
  selector: 'page-contact',
  templateUrl: 'contact.html'
})
export class ContactPage {
  isLogin: any;
  constructor(
    public navCtrl: NavController,
    public modalCtrl: ModalController,
    public shareProvider: ShareProvider,
  ) {
    this.isLogin = true;
    this._init();
  }
  jump() {
    if (this.isLogin) {
      console.log('login');
    }
  }
  _init() {
    let arr = ["1", "2", "3"];
    arr.forEach((el, index) => {
      console.log(el);
    })
    let obj = {
      a: "1",
      b: "2"
    }
    for (const el in obj) {
      console.log(el, obj[el]);
    }
    let obj1 = [
      { c: "1" },
      { d: "2" }
    ]
    for (const el of obj1) {
      console.log(el);
    }
  }
  //分享
  shares() {
    if (this.isLogin) {
      let modal = this.modalCtrl.create("SharePage");
      modal.present();
      modal.onDidDismiss(data => {
        this.shareTo(data.type);
      })
    }
  }
  shareTo(i) {
    let title = "您的好友分享了一个连接";
    let description = "有福同享真壕友~新手上路注册就送 188 元见面礼，更享 多重加息特权，你值得拥有!";
    let thumbImg = "https://img.zcool.cn/community/01dc0558ad38e6a801219c772b5fa8.jpg";
    let shareLink = "https:www.baidu.com";
    switch (i) {
      case 1: //微信好友
        this.shareProvider.wxShareWebpage(0, shareLink, title, description, thumbImg);
        break;
      case 2: //微信朋友圈
        this.shareProvider.wxShareWebpage(1, shareLink, title, description, thumbImg);
        break;
      case 3: //qq
        this.shareProvider.qqShareWebpage(0, shareLink, title, description, thumbImg);
        break;
      case 4: //qq空间
        this.shareProvider.wxShareWebpage(1, shareLink, title, description, thumbImg);
        break;
      case 5: //新浪
        this.shareProvider.wbShareWebpage(shareLink, title, description, thumbImg);
        break;
      default:
        break;
    }
  }
}
